import {
  RECEIVE_USER_LIST,
  RECEIVE_USER_LIAN,
  RECEIVE_GOODS,
} from "./mutation-types";
import { reqinformation, reqShopgoods, reqTel } from "../api";
export default {
  // 同步记录用户基本信息
  recordList({ commit }, userList) {
    commit(RECEIVE_USER_LIST, { userList });
  },
  // 异步获取用户基本信息
  async getuserLists({ commit }) {
    // 发送异步ajax请求
    const result = await reqinformation();
    if (result.code1 === 0) {
      const userList = result.data;
      commit(RECEIVE_USER_LIST, { userList });
    }
  },
  // 同步记录手机联系人
  recorduserlian({ commit }, userlian) {
    commit(RECEIVE_USER_LIAN, { userlian });
  },
  // 异步获取手机联系人
  async getuserlian({ commit }) {
    // 发送异步ajax请求
    const result = await reqTel();
    if (result.code1 === 0) {
      const userlian = result.data;
      commit(RECEIVE_USER_LIAN, { userlian });
    }
  },
  async getShopGoods({ commit }) {
    const result = await reqShopgoods();
    if (result.code === 0) {
      const goods = result.data;
      commit(RECEIVE_GOODS, { goods });
    }
  },
  setToken(context, token) {
    context.commit("SET_TOKEN", token);
  },
  setCardId(context, CardId) {
    context.commit("SET_CARDID", CardId);
  },
};
